package com.wz.compilerManual;

public class ProductionStack {
    private StackContent top;

    public boolean isNull(){
        return top == null;
    }

    public void push(StackContent stackContent){
        stackContent.setNext(top);
        top = stackContent;
    }

    public StackContent peek(){
        return new StackContent(top.getSymbol());
    }

    public StackContent pop(){
        StackContent stackContent = top;
        top = top.getNext();
        stackContent.setNext(null);
        return stackContent;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("stack inner view: ");
        StackContent stackContent = top;
        while (stackContent!=null){
            sb.append(stackContent.getSymbol().toString() + ",");
            stackContent = stackContent.getNext();
        }
        return sb.toString();
    }
}